/**
 * sysPayInfoServiceImpl
 * 项目名称:分秒金融
 *
 * @author dell
 *
 * 功能描述:系统支付设置管理
 * 
 * 历史版本:2017-05-16 v1.0.0 dell  创建:
 * 
 */
package com.fmjr.sys.sysPayInfo.service.impl;

import com.fmjr.common.base.exception.BusinessException;
import com.fmjr.sys.sysPayInfo.bean.SysPayInfo;
import com.fmjr.sys.sysPayInfo.dao.SysPayInfoDao;
import com.fmjr.sys.sysPayInfo.service.ISysPayInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service("sysPayInfoService")
@CacheConfig(cacheNames = "fmjrCache")
public class  SysPayInfoServiceImpl implements ISysPayInfoService {
	

	@Autowired
    private SysPayInfoDao sysPayInfoDao;

	/**
	 * 根据ID查询系统支付设置记录
	 * @author dell
	 * @param id
	 * @return domain
	 * @throws BusinessException
	 */
	@Cacheable(key="'selectSysPayInfo'")
	public SysPayInfo selectSysPayInfoById(Long id) throws BusinessException{
		return sysPayInfoDao.selectSysPayInfoById(id);
	}

	/**
	 *  删除系统支付设置记录
	 * @author dell	 
	 * @param id
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int deleteSysPayInfoById(Long id) throws BusinessException{
		return sysPayInfoDao.deleteSysPayInfoById(id);
	}
	
	/**
	 * 修改系统支付设置记录
	 * @author dell
	 * @param sysPayInfo
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	@CachePut(key="'selectSysPayInfo'")
	public SysPayInfo updateSysPayInfo(SysPayInfo sysPayInfo) throws BusinessException{
	
		int i = sysPayInfoDao.updateSysPayInfoSelective(sysPayInfo);
		if(i<0){
			throw new BusinessException(500,"修改 SysPayInfo 失败");
		}
		return sysPayInfo;
	}

	/**
	 * 新增系统支付设置记录
	 * @author dell
	 * @param sysPayInfo
	 * @return
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int createSysPayInfo(SysPayInfo sysPayInfo) throws BusinessException{
		return sysPayInfoDao.createSysPayInfo(sysPayInfo);
	}

	@Override
	@Cacheable(key="'selectSysPayInfo'")
	public SysPayInfo selectSysPayInfo() throws BusinessException {
		List<SysPayInfo> list=  sysPayInfoDao.selectSysPayInfoAll();
		if(list == null || list.size() == 0){
			throw  new BusinessException(500, "数据库没有配置支付信息  ");
		}
		return list.get(0);
	}
	

	

}
